package io.a.sql.smartsense;

import com.google.common.collect.TreeTraverser;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class Node {

    private String value;

    private List<Node> children;

    Node(String value, List<Node> children) {
        this.value = value;
        this.children = children;
    }

    public List<String> values() {
        List<String> list = new ArrayList<>();

        TreeTraverser<Node> treeTraverser = new TreeTraverser<Node>() {
            @Override
            public Iterable<Node> children(Node node) {
                return node.getChildren();
            }
        };
        for (Node node : treeTraverser.breadthFirstTraversal(this)) {
            list.add(node.getValue());
        }
        return list;
    }
}
